package com.team.kaidb.customview;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.InputType;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.team.kaidb.R;


/**
 * Created by Wj on 15/7/2.
 */
public class LabelInputView extends LinearLayout {

    private TextView tv_label;
    private EditText et_input;

    public LabelInputView(Context context) {
        super(context);
    }

    public LabelInputView(Context context, AttributeSet attrs) {
        super(context, attrs);
        addView(View.inflate(context, R.layout.label_input_view, null),
                new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        initView();
        loadParams(attrs);
    }

    private void initView() {
        tv_label = (TextView) findViewById(R.id.textView_label);
        et_input = (EditText) findViewById(R.id.editText_input);
    }

    private void loadParams(AttributeSet attrs) {
        TypedArray ta = this.getContext().obtainStyledAttributes(attrs,
                R.styleable.LabelInputView);
        String label = ta.getString(R.styleable.LabelInputView_label);
        if (label != null){
            tv_label.setText(label);
        }
        String hint = ta.getString(R.styleable.LabelInputView_input_hint);
        if (hint != null) {
            et_input.setHint(hint);
        }
//        int input_type = ta.getInt(R.styleable.LabelInputView_input_type, InputType.TYPE_CLASS_TEXT);
//        et_input.setInputType(input_type);
        ta.recycle();
    }

    /**
     * InputType.TYPE_CLASS_TEXT
     * InputType.TYPE_TEXT_VARIATION_PASSWORD
     * @param inputType
     */
    public void setInputType(int inputType){
        et_input.setInputType(inputType);
    }

    public String getText(){
        return et_input.getText().toString();
    }
    public void setText(String text){
        et_input.setText(""+text);
    }

}
